package cn.tedu.personal_patient.information.dao.persist.repository.impl;

import cn.tedu.personal_patient.information.dao.persist.mapper.PatientAddressMapper;
import cn.tedu.personal_patient.information.dao.persist.mapper.PatientMapper;
import cn.tedu.personal_patient.information.dao.persist.repository.IPatientRepository;
import cn.tedu.personal_patient.information.pojo.entity.Patient;
import cn.tedu.personal_patient.information.pojo.entity.PatientAddress;
import cn.tedu.personal_patient.information.pojo.vo.OutPatient;
import cn.tedu.personal_patient.information.pojo.vo.PatientListVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Slf4j
@Repository
public class PatientRepositoryImpl implements IPatientRepository {
    @Autowired
    private PatientMapper patientMapper;
    @Autowired
    private PatientAddressMapper patientAddressMapper;
    public PatientRepositoryImpl() {
        log.info("创建存储库对象：PatientRepositoryImpl");
    }

    @Override
    public List<PatientListVO> listByUserId(Long userId) {
        return patientMapper.list(userId);
    }

    @Override
    public int insert(Patient patient) {
        log.debug("开始执行【插入就诊人】的数据访问，参数：{}", patient);
        return patientMapper.insert(patient);
    }

    @Override
    public int update(Patient patient) {
        log.debug("开始执行【更新就诊人信息】的数据访问，参数：{}", patient);
        return patientMapper.update(patient);
    }

    @Override
    public int updateAddress(PatientAddress patientAddress) {
        return patientAddressMapper.updateAddress(patientAddress);
    }

    @Override
    public int delete(Long id) {
        return patientMapper.deleteById(id);
    }

    @Override
    public List<OutPatient> listUserId(Long userId) {
        return patientMapper.listByUserId(userId);
    }

}
